#include <iostream>
#include <thread>

void hello()
{
    std::string msg = "Hello func from thread id: ";
    std::cout << msg << std::this_thread::get_id() << std::endl;
}

class background_tast
{
public:
    void operator()() const // 函数调用符类型
    {
        std::string msg = "background_tast  from thread id: ";
        std::cout << msg << std::this_thread::get_id() << std::endl;
    }
};

int main()
{


    std::cout << "main thread id:  " << std::this_thread::get_id() << std::endl;
    std::thread t(hello);

    background_tast bt;
    // std::thread my_thread(bt);
    // std::thread my_thread(background_tast()); //error
    // std::thread my_thread((background_tast()));
    std::thread my_thread{background_tast()};

    // 使用lambda
    std::thread my_x([]
                     { std::string msg = "lambda  from thread id: " ;
                        std::cout <<  msg<< std::this_thread::get_id() << std::endl; });

    t.join();
    my_thread.join();
    my_x.join();
    std::cout << "hardware thread support: " << std::thread::hardware_concurrency();
}